#ifndef SHOWRECORD_H
#define SHOWRECORD_H

#include "sndarecord.pb.h"

class showkeyprimer
{
    public:
        static void show(ofstream & outfile, const keyprimer & disk)
        {
            outfile << "{";
            if(disk.has_host())
            {
                outfile << "'" << disk.host() << "',";
            }
            else
            {
                outfile << "'" << "',";
            }

            if(disk.has_diskid())
            {
                outfile << "'" << disk.diskid() << "',";
                
            }
            else
            {
                outfile << "'" << "',";
                
            }

            if(disk.has_chunk())
            {
                outfile << "'" << disk.chunk() << "',";
                
            }
            else
            {
                outfile << "'" << "',";
                
            }

            if(disk.has_id())
            {
                outfile << "'" << disk.id() << "',";
                
            }
            else
            {
                outfile << "'" << "',";
                
            }
            outfile << "}";
            
        }
        
};

class showrecord
{
    public:
        template<class T1>
        void show(ofstream & outfile, T1 & record)
        {
            outfile << "\"" << record.bucket() << "\"|" << "\""
                    << record.indexkey() << "\"|" << "\"" << record.version()
                    << "\"|" << "\"" << record.del_mark() << "\"|" << "\""
                    << record.user_time_stamp() << "\"|" << "\""
                    << record.internal_time_stamp() << "\"|" << "\""
                    << record.content_length() << "\"|" << "\""
                    << record.value_checksum() << "\"|" << "\""
                    << record.row_checksum() << "\"|";
            keyprimer emptyprimer;
            
            if(record.has_disk1())
            {
                showkeyprimer::show(outfile, record.disk1());
            }
            else
            {
                showkeyprimer::show(outfile, emptyprimer);
            }

            if(record.has_disk2())
            {
                showkeyprimer::show(outfile, record.disk2());
            }
            else
            {
                showkeyprimer::show(outfile, emptyprimer);
            }

            if(record.has_disk3())
            {
                showkeyprimer::show(outfile, record.disk3());
            }
            else
            {
                showkeyprimer::show(outfile, emptyprimer);
            }
            outfile << "\"" << record.system_metas() << "\"|" << "\""
                    << record.user_metas() << "\"";
            
            outfile << std::endl;
        }
};

#endif
